package com.jml.callable;


/**
 *
 */

public class Join和Wait和Notify {

    final static Thread t2 = new T2();

    public static class T1 extends Thread {
        public void run() {
            synchronized (t2) {
                System.out.println(System.currentTimeMillis() + ":T1 start! ");
                try {
                    System.out.println(System.currentTimeMillis() + ":T1 wait for object ");
                    t2.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(System.currentTimeMillis() + ":T1 end!");
            }
        }
    }

    public static class T2 extends Thread {

        public void run() {
            try {
                System.out.println("T2 begin");
                Thread.sleep(2000);
                System.out.println("T2 end");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new T1();
        t1.start();
        t2.start();
        t2.join();
        System.out.println("main  end!!!");
    }
}